<template>
  <div class="left">
    <h1>Username</h1>
    <input type="text" v-model="username" />

    <h1>ResetQuestion</h1>
    <select type="text" v-model="question">
      <option value="1">最喜欢的运动</option>
      <option value="2">最喜欢的食物</option>
      <option value="3">最喜欢的音乐</option>
      <option value="4">最喜欢的电影</option>
    </select>
    <h1>ResetAnswer</h1>
    <input type="text" v-model="answer" />
    <h1>NewPassword</h1>
    <input type="password" v-model="password" />
    <h1>Comfirm</h1>
    <input type="password" v-model="rePassword" />

    <div class="submit" @click="re">RESET</div>
    <a href="#" @click="toLogin">BackLogin</a>
  </div>
</template>
    
    <script>
import { mapActions,mapState} from "vuex";

export default {
  name: "Register",
  data() {
    return {
      username: "",
      question: 2,
      answer: "",
      password: "",
      rePassword: "",
    };
  },
  computed: {
    ...mapState("reset", ["code","message"]),
  },
  methods: {
    ...mapActions("reset", ["reset"]),
    re() {
      if (this.username.trim() == "") {
        alert("Please enter username");
        return;
      }
      if (this.answer.trim() == "") {
        alert("Please enter answer");
        return;
      }
      if (this.password.trim() == "") {
        alert("Please enter password");
        return;
      }
      if (this.rePassword.trim() == "") {
        alert("Please comfirm password");
        return;
      }
      if (this.password != this.rePassword) {
        alert("两次密码输入不一致");
        return;
      }
      this.reset({
        username: this.username,
        answer: this.answer,
        password: this.password,
      });

      setTimeout(() => {

        if (this.code ===-1) {
          alert("请求超时");
          return;
        }
        alert(this.message);
        if (this.code === 200) {
          this.$bus.$emit("changePosition", 0);
          this.$bus.$emit("changeTitle", 0);
        }
      }, 1000);
      this.usernam= ""
      this.passwor= ""
      this.rePassword=""
      this.question=1
      this.answe= ""
    },
    toLogin() {
      this.$bus.$emit("changePosition", 0);
      this.$bus.$emit("changeTitle", 0);
    },
  },
};
</script>
    
    <style scoped>
.left {
  width: 50%;
  height: 100%;
  position: absolute;
  top: 0;
  right: 0;
  border-radius: 0 20px 20px 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: left;
  transform: translate(-100%);
  /* backdrop-filter: blur(100px); */
}
.left h1 {
  font-family: "Times New Roman", Times, serif;
  font-size: 1.1em;
  color: rgb(92, 183, 234);
  margin-left: 50px;
  margin-bottom: 10px;
  text-shadow: 0 0 5px rgb(92, 183, 234, 0.5);
}
.left input {
  font-family: "Times New Roman", Times, serif;
  position: relative;
  margin-left: 50px;
  margin-bottom: 0px;
  width: 250px;
  height: 30px;
  box-sizing: border-box;
  color: rgb(92, 183, 234);

  font-size: 1em;

  padding-left: 5px;
  outline: none;
  border-top: 0;
  border-right: 0;
  border-left: 0;
  border-bottom-color: rgba(92, 183, 234);
  border-bottom-width: 3px;

  transition: all 0.5s;

  box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
  border-radius: 10px;

  caret-color: rgba(92, 183, 234);
}
.left input:nth-of-type(4) {
  margin-bottom: 20px;
}
.left input:focus {
  transform: scale(1.05);
  border-color: rgba(92, 183, 234);

  outline: 0;
}
select {
  font-family: "仿宋", Times, serif;
  position: relative;
  margin-left: 50px;
  margin-bottom: 0px;
  width: 250px;
  height: 30px;
  box-sizing: border-box;
  color: rgb(92, 183, 234);

  font-size: 1em;
  padding-left: 5px;
  outline: none;
  border-top: 0;
  border-right: 0;
  border-left: 0;
  border-bottom-color: rgba(92, 183, 234);
  border-bottom-width: 3px;

  /* appearance: none; */
  transition: all 0.5s;

  box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
  border-radius: 10px;
}
.submit {
  font-family: "Times New Roman", Times, serif;
  position: relative;
  box-sizing: border-box;
  margin-left: 50px;
  top: 10px;
  width: 250px;
  height: 40px;
  border-radius: 10px;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
  background-color: rgb(92, 183, 234);
  line-height: 40px;
  text-align: center;
  color: white;
  text-transform: uppercase;
  font-size: 1.5em;
  text-shadow: 0 0 10px rgb(0, 0, 0, 0.5);
  transition: all 0.5s;
  cursor: pointer;
  margin-bottom: 50px;
}

.submit:hover {
  transform: scale(1.05);
}
.left a:nth-of-type(1) {
  position: absolute;
  left: 55px;
  bottom: 15px;
  font-family: "Times New Roman", Times, serif;
  font-size: 1em;
  color: rgb(92, 183, 234);
  text-align: left;
}
</style>